<!DOCTYPE HTML>
<html lang="en" >
    <!-- Start book Python爬虫课程讲义 -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>Request/Response | Python爬虫课程讲义</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        <meta name="author" content="BigCat">
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-tbfed-pagefooter/footer.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../file/part04/4.8.html" />
    
    
    <link rel="prev" href="../../file/part04/4.6.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="4.7"
        data-chapter-title="Request/Response"
        data-filepath="file/part04/4.7.md"
        data-basepath="../.."
        data-revision="Thu Feb 09 2017 09:48:59 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        传智播客Python学院爬虫课程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="file/part01/1.html">
            
                
                    <a href="../../file/part01/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        爬虫原理与数据抓取
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="file/part01/1.1.html">
            
                
                    <a href="../../file/part01/1.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        (了解)通用爬虫和聚焦爬虫
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="file/part01/1.2.html">
            
                
                    <a href="../../file/part01/1.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        (复习)HTTP/HTTPS的请求与响应
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="file/part01/1.3.html">
            
                
                    <a href="../../file/part01/1.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        HTTP/HTTPS抓包工具-Fiddler
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="file/part01/1.4.html">
            
                
                    <a href="../../file/part01/1.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        urllib2模块的基本使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="file/part01/1.5.html">
            
                
                    <a href="../../file/part01/1.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        urllib2：GET请求和POST请求
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="file/part01/1.6.html">
            
                
                    <a href="../../file/part01/1.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        urllib2：Handler处理器和自定义Opener
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="file/part01/1.7.html">
            
                
                    <a href="../../file/part01/1.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.</b>
                        
                        urllib2：URLError与HTTPError
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="file/part01/1.8.html">
            
                
                    <a href="../../file/part01/1.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.8.</b>
                        
                        Requests模块
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="file/part02/2.html">
            
                
                    <a href="../../file/part02/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        非结构化数据与结构化数据提取
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="file/part02/2.1.html">
            
                
                    <a href="../../file/part02/2.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        正则表达式re模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="file/part02/2.2.html">
            
                
                    <a href="../../file/part02/2.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        案例：使用正则表达式的爬虫
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="file/part02/2.3.html">
            
                
                    <a href="../../file/part02/2.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        XPath与lxml类库
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="file/part02/2.4.html">
            
                
                    <a href="../../file/part02/2.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        案例：使用XPath的爬虫
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="file/part02/2.5.html">
            
                
                    <a href="../../file/part02/2.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        BeautifulSoup4 解析器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="file/part02/2.6.html">
            
                
                    <a href="../../file/part02/2.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        案例：使用bs4的爬虫
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="file/part02/2.7.html">
            
                
                    <a href="../../file/part02/2.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        JSON模块与JsonPath
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="file/part02/2.8.html">
            
                
                    <a href="../../file/part02/2.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        糗事百科案例
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="file/part02/2.9.html">
            
                
                    <a href="../../file/part02/2.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.9.</b>
                        
                        多线程爬虫案例
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="file/part03/3.html">
            
                
                    <a href="../../file/part03/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        动态HTML处理和机器图像识别
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="file/part03/3.1.html">
            
                
                    <a href="../../file/part03/3.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        动态HTML介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="file/part03/3.2.html">
            
                
                    <a href="../../file/part03/3.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        Selenium与PhantomJS
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="file/part03/3.3.html">
            
                
                    <a href="../../file/part03/3.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        案例一：网站模拟登录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="file/part03/3.4.html">
            
                
                    <a href="../../file/part03/3.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        案例二：动态页面模拟点击
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="file/part03/3.5.html">
            
                
                    <a href="../../file/part03/3.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        案例三：执行JavaScript语句
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="file/part03/3.6.html">
            
                
                    <a href="../../file/part03/3.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        机器视觉与Tesseract介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="file/part03/3.7.html">
            
                
                    <a href="../../file/part03/3.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        处理一些格式规范的文字
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="file/part03/3.8.html">
            
                
                    <a href="../../file/part03/3.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        案例：尝试对验证码进行机器识别处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="file/part03/3.9.html">
            
                
                    <a href="../../file/part03/3.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        机器学习：训练Tesseract
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="file/part04/4.html">
            
                
                    <a href="../../file/part04/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        Scrapy框架
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="file/part04/4.1.html">
            
                
                    <a href="../../file/part04/4.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        配置安装
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="file/part04/4.2.html">
            
                
                    <a href="../../file/part04/4.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        入门案例
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="file/part04/4.3.html">
            
                
                    <a href="../../file/part04/4.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        Scrapy Shell
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="file/part04/4.4.html">
            
                
                    <a href="../../file/part04/4.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        Item Pipeline
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="file/part04/4.5.html">
            
                
                    <a href="../../file/part04/4.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        Spiders
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="file/part04/4.6.html">
            
                
                    <a href="../../file/part04/4.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        CrawlSpiders
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="4.7" data-path="file/part04/4.7.html">
            
                
                    <a href="../../file/part04/4.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.7.</b>
                        
                        Request/Response
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="file/part04/4.8.html">
            
                
                    <a href="../../file/part04/4.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.8.</b>
                        
                        Downloader Middlewares
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="file/part04/4.9.html">
            
                
                    <a href="../../file/part04/4.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.</b>
                        
                        Settings
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="file/part05/5.html">
            
                
                    <a href="../../file/part05/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        Scrapy实战项目
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="file/part05/5.1.html">
            
                
                    <a href="../../file/part05/5.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        (案例一)手机App抓包爬虫
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="file/part05/5.2.html">
            
                
                    <a href="../../file/part05/5.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        (案例二)阳光热线问政平台爬虫
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="file/part05/5.3.html">
            
                
                    <a href="../../file/part05/5.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        (案例三)新浪网分类资讯爬虫
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="file/part05/5.4.html">
            
                
                    <a href="../../file/part05/5.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        (案例四)图片下载器爬虫
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="file/part05/5.5.html">
            
                
                    <a href="../../file/part05/5.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        (案例五)将数据保存在MongoDB中
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="file/part05/5.6.html">
            
                
                    <a href="../../file/part05/5.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        (案例六)三种scrapy模拟登陆策略
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="file/part05/5.7.html">
            
                
                    <a href="../../file/part05/5.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        附：通过Fiddler进行手机抓包方法
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="file/part06/6.html">
            
                
                    <a href="../../file/part06/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        scrapy-redis分布式组件
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="file/part06/6.1.html">
            
                
                    <a href="../../file/part06/6.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        源码分析参考：Connection
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="file/part06/6.2.html">
            
                
                    <a href="../../file/part06/6.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        源码分析参考：Dupefilter
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="file/part06/6.3.html">
            
                
                    <a href="../../file/part06/6.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        源码分析参考：Picklecompat
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="file/part06/6.4.html">
            
                
                    <a href="../../file/part06/6.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        源码分析参考：Pipelines
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="file/part06/6.5.html">
            
                
                    <a href="../../file/part06/6.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        源码分析参考：Queue
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="file/part06/6.6.html">
            
                
                    <a href="../../file/part06/6.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        源码分析参考：Scheduler
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="file/part06/6.7.html">
            
                
                    <a href="../../file/part06/6.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                        源码分析参考：Spider
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="file/part07/7.html">
            
                
                    <a href="../../file/part07/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        scrapy-redis实战
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="file/part07/7.1.html">
            
                
                    <a href="../../file/part07/7.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        源码自带项目说明
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="file/part07/7.2.html">
            
                
                    <a href="../../file/part07/7.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        有缘网分布式爬虫项目1
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="file/part07/7.3.html">
            
                
                    <a href="../../file/part07/7.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        有缘网分布式爬虫项目2
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="file/part07/7.4.html">
            
                
                    <a href="../../file/part07/7.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        处理Redis里的数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="file/part07/7.5.html">
            
                
                    <a href="../../file/part07/7.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.5.</b>
                        
                        尝试改写新浪网分类资讯爬虫1
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.6" data-path="file/part07/7.6.html">
            
                
                    <a href="../../file/part07/7.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.6.</b>
                        
                        尝试改写新浪网分类资讯爬虫2
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.7" data-path="file/part07/7.7.html">
            
                
                    <a href="../../file/part07/7.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.7.</b>
                        
                        IT桔子分布式项目1
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.8" data-path="file/part07/7.8.html">
            
                
                    <a href="../../file/part07/7.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.8.</b>
                        
                        IT桔子分布式项目2
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" data-path="file/duanzi/duanzi.html">
            
                
                    <a href="../../file/duanzi/duanzi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        课余段子
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >Python爬虫课程讲义</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="request">Request</h1>
<p>Request &#x90E8;&#x5206;&#x6E90;&#x7801;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x90E8;&#x5206;&#x4EE3;&#x7801;</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Request</span><span class="hljs-params">(object_ref)</span>:</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, url, callback=None, method=<span class="hljs-string">&apos;GET&apos;</span>, headers=None, body=None, 
                 cookies=None, meta=None, encoding=<span class="hljs-string">&apos;utf-8&apos;</span>, priority=<span class="hljs-number">0</span>,
                 dont_filter=False, errback=None)</span>:</span>

        self._encoding = encoding  <span class="hljs-comment"># this one has to be set first</span>
        self.method = str(method).upper()
        self._set_url(url)
        self._set_body(body)
        <span class="hljs-keyword">assert</span> isinstance(priority, int), <span class="hljs-string">&quot;Request priority not an integer: %r&quot;</span> % priority
        self.priority = priority

        <span class="hljs-keyword">assert</span> callback <span class="hljs-keyword">or</span> <span class="hljs-keyword">not</span> errback, <span class="hljs-string">&quot;Cannot use errback without a callback&quot;</span>
        self.callback = callback
        self.errback = errback

        self.cookies = cookies <span class="hljs-keyword">or</span> {}
        self.headers = Headers(headers <span class="hljs-keyword">or</span> {}, encoding=encoding)
        self.dont_filter = dont_filter

        self._meta = dict(meta) <span class="hljs-keyword">if</span> meta <span class="hljs-keyword">else</span> <span class="hljs-keyword">None</span>

<span class="hljs-decorator">    @property</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">meta</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-keyword">if</span> self._meta <span class="hljs-keyword">is</span> <span class="hljs-keyword">None</span>:
            self._meta = {}
        <span class="hljs-keyword">return</span> self._meta
</code></pre>
<p>&#x5176;&#x4E2D;&#xFF0C;&#x6BD4;&#x8F83;&#x5E38;&#x7528;&#x7684;&#x53C2;&#x6570;&#xFF1A;</p>
<pre><code class="lang-python">url: &#x5C31;&#x662F;&#x9700;&#x8981;&#x8BF7;&#x6C42;&#xFF0C;&#x5E76;&#x8FDB;&#x884C;&#x4E0B;&#x4E00;&#x6B65;&#x5904;&#x7406;&#x7684;url

callback: &#x6307;&#x5B9A;&#x8BE5;&#x8BF7;&#x6C42;&#x8FD4;&#x56DE;&#x7684;Response&#xFF0C;&#x7531;&#x90A3;&#x4E2A;&#x51FD;&#x6570;&#x6765;&#x5904;&#x7406;&#x3002;

method: &#x8BF7;&#x6C42;&#x4E00;&#x822C;&#x4E0D;&#x9700;&#x8981;&#x6307;&#x5B9A;&#xFF0C;&#x9ED8;&#x8BA4;GET&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x8BBE;&#x7F6E;&#x4E3A;<span class="hljs-string">&quot;GET&quot;</span>, <span class="hljs-string">&quot;POST&quot;</span>, <span class="hljs-string">&quot;PUT&quot;</span>&#x7B49;&#xFF0C;&#x4E14;&#x4FDD;&#x8BC1;&#x5B57;&#x7B26;&#x4E32;&#x5927;&#x5199;

headers: &#x8BF7;&#x6C42;&#x65F6;&#xFF0C;&#x5305;&#x542B;&#x7684;&#x5934;&#x6587;&#x4EF6;&#x3002;&#x4E00;&#x822C;&#x4E0D;&#x9700;&#x8981;&#x3002;&#x5185;&#x5BB9;&#x4E00;&#x822C;&#x5982;&#x4E0B;&#xFF1A;
        <span class="hljs-comment"># &#x81EA;&#x5DF1;&#x5199;&#x8FC7;&#x722C;&#x866B;&#x7684;&#x80AF;&#x5B9A;&#x77E5;&#x9053;</span>
        Host: media.readthedocs.org
        User-Agent: Mozilla/<span class="hljs-number">5.0</span> (Windows NT <span class="hljs-number">6.2</span>; WOW64; rv:<span class="hljs-number">33.0</span>) Gecko/<span class="hljs-number">20100101</span> Firefox/<span class="hljs-number">33.0</span>
        Accept: text/css,*/*;q=<span class="hljs-number">0.1</span>
        Accept-Language: zh-cn,zh;q=<span class="hljs-number">0.8</span>,en-us;q=<span class="hljs-number">0.5</span>,en;q=<span class="hljs-number">0.3</span>
        Accept-Encoding: gzip, deflate
        Referer: http://scrapy-chs.readthedocs.org/zh_CN/<span class="hljs-number">0.24</span>/
        Cookie: _ga=GA1<span class="hljs-number">.2</span><span class="hljs-number">.1612165614</span><span class="hljs-number">.1415584110</span>;
        Connection: keep-alive
        If-Modified-Since: Mon, <span class="hljs-number">25</span> Aug <span class="hljs-number">2014</span> <span class="hljs-number">21</span>:<span class="hljs-number">59</span>:<span class="hljs-number">35</span> GMT
        Cache-Control: max-age=<span class="hljs-number">0</span>

meta: &#x6BD4;&#x8F83;&#x5E38;&#x7528;&#xFF0C;&#x5728;&#x4E0D;&#x540C;&#x7684;&#x8BF7;&#x6C42;&#x4E4B;&#x95F4;&#x4F20;&#x9012;&#x6570;&#x636E;&#x4F7F;&#x7528;&#x7684;&#x3002;&#x5B57;&#x5178;dict&#x578B;

        request_with_cookies = Request(
            url=<span class="hljs-string">&quot;http://www.example.com&quot;</span>,
            cookies={<span class="hljs-string">&apos;currency&apos;</span>: <span class="hljs-string">&apos;USD&apos;</span>, <span class="hljs-string">&apos;country&apos;</span>: <span class="hljs-string">&apos;UY&apos;</span>},
            meta={<span class="hljs-string">&apos;dont_merge_cookies&apos;</span>: <span class="hljs-keyword">True</span>}
        )

encoding: &#x4F7F;&#x7528;&#x9ED8;&#x8BA4;&#x7684; <span class="hljs-string">&apos;utf-8&apos;</span> &#x5C31;&#x884C;&#x3002;

dont_filter: &#x8868;&#x660E;&#x8BE5;&#x8BF7;&#x6C42;&#x4E0D;&#x7531;&#x8C03;&#x5EA6;&#x5668;&#x8FC7;&#x6EE4;&#x3002;&#x8FD9;&#x662F;&#x5F53;&#x4F60;&#x60F3;&#x4F7F;&#x7528;&#x591A;&#x6B21;&#x6267;&#x884C;&#x76F8;&#x540C;&#x7684;&#x8BF7;&#x6C42;,&#x5FFD;&#x7565;&#x91CD;&#x590D;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#x3002;&#x9ED8;&#x8BA4;&#x4E3A;<span class="hljs-keyword">False</span>&#x3002;

errback: &#x6307;&#x5B9A;&#x9519;&#x8BEF;&#x5904;&#x7406;&#x51FD;&#x6570;
</code></pre>
<h1 id="response">Response</h1>
<pre><code class="lang-python"><span class="hljs-comment"># &#x90E8;&#x5206;&#x4EE3;&#x7801;</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Response</span><span class="hljs-params">(object_ref)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, url, status=<span class="hljs-number">200</span>, headers=None, body=<span class="hljs-string">&apos;&apos;</span>, flags=None, request=None)</span>:</span>
        self.headers = Headers(headers <span class="hljs-keyword">or</span> {})
        self.status = int(status)
        self._set_body(body)
        self._set_url(url)
        self.request = request
        self.flags = [] <span class="hljs-keyword">if</span> flags <span class="hljs-keyword">is</span> <span class="hljs-keyword">None</span> <span class="hljs-keyword">else</span> list(flags)

<span class="hljs-decorator">    @property</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">meta</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-keyword">try</span>:
            <span class="hljs-keyword">return</span> self.request.meta
        <span class="hljs-keyword">except</span> AttributeError:
            <span class="hljs-keyword">raise</span> AttributeError(<span class="hljs-string">&quot;Response.meta not available, this response &quot;</span> \
                <span class="hljs-string">&quot;is not tied to any request&quot;</span>)
</code></pre>
<p>&#x5927;&#x90E8;&#x5206;&#x53C2;&#x6570;&#x548C;&#x4E0A;&#x9762;&#x7684;&#x5DEE;&#x4E0D;&#x591A;&#xFF1A;</p>
<pre><code class="lang-python">
status: &#x54CD;&#x5E94;&#x7801;
_set_body(body)&#xFF1A; &#x54CD;&#x5E94;&#x4F53;
_set_url(url)&#xFF1A;&#x54CD;&#x5E94;url
self.request = request
</code></pre>
<h2 id="&#x53D1;&#x9001;post&#x8BF7;&#x6C42;">&#x53D1;&#x9001;POST&#x8BF7;&#x6C42;</h2>
<ul>
<li><p>&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>yield scrapy.FormRequest(url, formdata, callback)</code>&#x65B9;&#x6CD5;&#x53D1;&#x9001;POST&#x8BF7;&#x6C42;&#x3002;</p>
</li>
<li><p>&#x5982;&#x679C;&#x5E0C;&#x671B;&#x7A0B;&#x5E8F;&#x6267;&#x884C;&#x4E00;&#x5F00;&#x59CB;&#x5C31;&#x53D1;&#x9001;POST&#x8BF7;&#x6C42;&#xFF0C;&#x53EF;&#x4EE5;&#x91CD;&#x5199;Spider&#x7C7B;&#x7684;<code>start_requests(self)</code> &#x65B9;&#x6CD5;&#xFF0C;&#x5E76;&#x4E14;&#x4E0D;&#x518D;&#x8C03;&#x7528;start_urls&#x91CC;&#x7684;url&#x3002;</p>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">mySpider</span><span class="hljs-params">(scrapy.Spider)</span>:</span>
    <span class="hljs-comment"># start_urls = [&quot;http://www.example.com/&quot;]</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">start_requests</span><span class="hljs-params">(self)</span>:</span>
        url = <span class="hljs-string">&apos;http://www.renren.com/PLogin.do&apos;</span>

        <span class="hljs-comment"># FormRequest &#x662F;Scrapy&#x53D1;&#x9001;POST&#x8BF7;&#x6C42;&#x7684;&#x65B9;&#x6CD5;</span>
        <span class="hljs-keyword">yield</span> scrapy.FormRequest(
            url = url,
            formdata = {<span class="hljs-string">&quot;email&quot;</span> : <span class="hljs-string">&quot;mr_mao_hacker@163.com&quot;</span>, <span class="hljs-string">&quot;password&quot;</span> : <span class="hljs-string">&quot;axxxxxxxe&quot;</span>},
            callback = self.parse_page
        )
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">parse_page</span><span class="hljs-params">(self, response)</span>:</span>
        <span class="hljs-comment"># do something</span>
</code></pre>
<h2 id="&#x6A21;&#x62DF;&#x767B;&#x9646;">&#x6A21;&#x62DF;&#x767B;&#x9646;</h2>
<p>&#x4F7F;&#x7528;FormRequest.from_response()&#x65B9;&#x6CD5;<a href="http://docs.pythontab.com/scrapy/scrapy0.24/topics/request-response.html#topics-request-response-ref-request-userlogin" target="_blank">&#x6A21;&#x62DF;&#x7528;&#x6237;&#x767B;&#x5F55;</a></p>
<blockquote>
<p>&#x901A;&#x5E38;&#x7F51;&#x7AD9;&#x901A;&#x8FC7; <input type="hidden"> &#x5B9E;&#x73B0;&#x5BF9;&#x67D0;&#x4E9B;&#x8868;&#x5355;&#x5B57;&#x6BB5;&#xFF08;&#x5982;&#x6570;&#x636E;&#x6216;&#x662F;&#x767B;&#x5F55;&#x754C;&#x9762;&#x4E2D;&#x7684;&#x8BA4;&#x8BC1;&#x4EE4;&#x724C;&#x7B49;&#xFF09;&#x7684;&#x9884;&#x586B;&#x5145;&#x3002; </p>
<p>&#x4F7F;&#x7528;Scrapy&#x6293;&#x53D6;&#x7F51;&#x9875;&#x65F6;&#xFF0C;&#x5982;&#x679C;&#x60F3;&#x8981;&#x9884;&#x586B;&#x5145;&#x6216;&#x91CD;&#x5199;&#x50CF;&#x7528;&#x6237;&#x540D;&#x3001;&#x7528;&#x6237;&#x5BC6;&#x7801;&#x8FD9;&#x4E9B;&#x8868;&#x5355;&#x5B57;&#x6BB5;&#xFF0C; &#x53EF;&#x4EE5;&#x4F7F;&#x7528; FormRequest.from_response() &#x65B9;&#x6CD5;&#x5B9E;&#x73B0;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x662F;&#x4F7F;&#x7528;&#x8FD9;&#x79CD;&#x65B9;&#x6CD5;&#x7684;&#x722C;&#x866B;&#x4F8B;&#x5B50;:</p>
</blockquote>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> scrapy

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">LoginSpider</span><span class="hljs-params">(scrapy.Spider)</span>:</span>
    name = <span class="hljs-string">&apos;example.com&apos;</span>
    start_urls = [<span class="hljs-string">&apos;http://www.example.com/users/login.php&apos;</span>]

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">parse</span><span class="hljs-params">(self, response)</span>:</span>
        <span class="hljs-keyword">return</span> scrapy.FormRequest.from_response(
            response,
            formdata={<span class="hljs-string">&apos;username&apos;</span>: <span class="hljs-string">&apos;john&apos;</span>, <span class="hljs-string">&apos;password&apos;</span>: <span class="hljs-string">&apos;secret&apos;</span>},
            callback=self.after_login
        )

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">after_login</span><span class="hljs-params">(self, response)</span>:</span>
        <span class="hljs-comment"># check login succeed before going on</span>
        <span class="hljs-keyword">if</span> <span class="hljs-string">&quot;authentication failed&quot;</span> <span class="hljs-keyword">in</span> response.body:
            self.log(<span class="hljs-string">&quot;Login failed&quot;</span>, level=log.ERROR)
            <span class="hljs-keyword">return</span>

        <span class="hljs-comment"># continue scraping with authenticated session...</span>
</code></pre>
<h2 id="&#x77E5;&#x4E4E;&#x722C;&#x866B;&#x6848;&#x4F8B;&#x53C2;&#x8003;&#xFF1A;">&#x77E5;&#x4E4E;&#x722C;&#x866B;&#x6848;&#x4F8B;&#x53C2;&#x8003;&#xFF1A;</h2>
<h4 id="zhihuspiderpy&#x722C;&#x866B;&#x4EE3;&#x7801;">zhihuSpider.py&#x722C;&#x866B;&#x4EE3;&#x7801;</h4>
<pre><code class="lang-python"><span class="hljs-comment">#!/usr/bin/env python</span>
<span class="hljs-comment"># -*- coding:utf-8 -*-</span>
<span class="hljs-keyword">from</span> scrapy.spiders <span class="hljs-keyword">import</span> CrawlSpider, Rule
<span class="hljs-keyword">from</span> scrapy.selector <span class="hljs-keyword">import</span> Selector
<span class="hljs-keyword">from</span> scrapy.linkextractors <span class="hljs-keyword">import</span> LinkExtractor
<span class="hljs-keyword">from</span> scrapy <span class="hljs-keyword">import</span> Request, FormRequest
<span class="hljs-keyword">from</span> zhihu.items <span class="hljs-keyword">import</span> ZhihuItem

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ZhihuSipder</span><span class="hljs-params">(CrawlSpider)</span> :</span>
    name = <span class="hljs-string">&quot;zhihu&quot;</span>
    allowed_domains = [<span class="hljs-string">&quot;www.zhihu.com&quot;</span>]
    start_urls = [
        <span class="hljs-string">&quot;http://www.zhihu.com&quot;</span>
    ]
    rules = (
        Rule(LinkExtractor(allow = (<span class="hljs-string">&apos;/question/\d+#.*?&apos;</span>, )), callback = <span class="hljs-string">&apos;parse_page&apos;</span>, follow = <span class="hljs-keyword">True</span>),
        Rule(LinkExtractor(allow = (<span class="hljs-string">&apos;/question/\d+&apos;</span>, )), callback = <span class="hljs-string">&apos;parse_page&apos;</span>, follow = <span class="hljs-keyword">True</span>),
    )

    headers = {
    <span class="hljs-string">&quot;Accept&quot;</span>: <span class="hljs-string">&quot;*/*&quot;</span>,
    <span class="hljs-string">&quot;Accept-Encoding&quot;</span>: <span class="hljs-string">&quot;gzip,deflate&quot;</span>,
    <span class="hljs-string">&quot;Accept-Language&quot;</span>: <span class="hljs-string">&quot;en-US,en;q=0.8,zh-TW;q=0.6,zh;q=0.4&quot;</span>,
    <span class="hljs-string">&quot;Connection&quot;</span>: <span class="hljs-string">&quot;keep-alive&quot;</span>,
    <span class="hljs-string">&quot;Content-Type&quot;</span>:<span class="hljs-string">&quot; application/x-www-form-urlencoded; charset=UTF-8&quot;</span>,
    <span class="hljs-string">&quot;User-Agent&quot;</span>: <span class="hljs-string">&quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36&quot;</span>,
    <span class="hljs-string">&quot;Referer&quot;</span>: <span class="hljs-string">&quot;http://www.zhihu.com/&quot;</span>
    }

    <span class="hljs-comment">#&#x91CD;&#x5199;&#x4E86;&#x722C;&#x866B;&#x7C7B;&#x7684;&#x65B9;&#x6CD5;, &#x5B9E;&#x73B0;&#x4E86;&#x81EA;&#x5B9A;&#x4E49;&#x8BF7;&#x6C42;, &#x8FD0;&#x884C;&#x6210;&#x529F;&#x540E;&#x4F1A;&#x8C03;&#x7528;callback&#x56DE;&#x8C03;&#x51FD;&#x6570;</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">start_requests</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-keyword">return</span> [Request(<span class="hljs-string">&quot;https://www.zhihu.com/login&quot;</span>, meta = {<span class="hljs-string">&apos;cookiejar&apos;</span> : <span class="hljs-number">1</span>}, callback = self.post_login)]

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">post_login</span><span class="hljs-params">(self, response)</span>:</span>
        <span class="hljs-keyword">print</span> <span class="hljs-string">&apos;Preparing login&apos;</span>
        <span class="hljs-comment">#&#x4E0B;&#x9762;&#x8FD9;&#x53E5;&#x8BDD;&#x7528;&#x4E8E;&#x6293;&#x53D6;&#x8BF7;&#x6C42;&#x7F51;&#x9875;&#x540E;&#x8FD4;&#x56DE;&#x7F51;&#x9875;&#x4E2D;&#x7684;_xsrf&#x5B57;&#x6BB5;&#x7684;&#x6587;&#x5B57;, &#x7528;&#x4E8E;&#x6210;&#x529F;&#x63D0;&#x4EA4;&#x8868;&#x5355;</span>
        xsrf = Selector(response).xpath(<span class="hljs-string">&apos;//input[@name=&quot;_xsrf&quot;]/@value&apos;</span>).extract()[<span class="hljs-number">0</span>]
        <span class="hljs-keyword">print</span> xsrf
        <span class="hljs-comment">#FormRequeset.from_response&#x662F;Scrapy&#x63D0;&#x4F9B;&#x7684;&#x4E00;&#x4E2A;&#x51FD;&#x6570;, &#x7528;&#x4E8E;post&#x8868;&#x5355;</span>
        <span class="hljs-comment">#&#x767B;&#x9646;&#x6210;&#x529F;&#x540E;, &#x4F1A;&#x8C03;&#x7528;after_login&#x56DE;&#x8C03;&#x51FD;&#x6570;</span>
        <span class="hljs-keyword">return</span> [FormRequest.from_response(response,   <span class="hljs-comment">#&quot;http://www.zhihu.com/login&quot;,</span>
                            meta = {<span class="hljs-string">&apos;cookiejar&apos;</span> : response.meta[<span class="hljs-string">&apos;cookiejar&apos;</span>]},
                            headers = self.headers,  <span class="hljs-comment">#&#x6CE8;&#x610F;&#x6B64;&#x5904;&#x7684;headers</span>
                            formdata = {
                            <span class="hljs-string">&apos;_xsrf&apos;</span>: xsrf,
                            <span class="hljs-string">&apos;email&apos;</span>: <span class="hljs-string">&apos;1095511864@qq.com&apos;</span>,
                            <span class="hljs-string">&apos;password&apos;</span>: <span class="hljs-string">&apos;123456&apos;</span>
                            },
                            callback = self.after_login,
                            dont_filter = <span class="hljs-keyword">True</span>
                            )]

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">after_login</span><span class="hljs-params">(self, response)</span> :</span>
        <span class="hljs-keyword">for</span> url <span class="hljs-keyword">in</span> self.start_urls :
            <span class="hljs-keyword">yield</span> self.make_requests_from_url(url)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">parse_page</span><span class="hljs-params">(self, response)</span>:</span>
        problem = Selector(response)
        item = ZhihuItem()
        item[<span class="hljs-string">&apos;url&apos;</span>] = response.url
        item[<span class="hljs-string">&apos;name&apos;</span>] = problem.xpath(<span class="hljs-string">&apos;//span[@class=&quot;name&quot;]/text()&apos;</span>).extract()
        <span class="hljs-keyword">print</span> item[<span class="hljs-string">&apos;name&apos;</span>]
        item[<span class="hljs-string">&apos;title&apos;</span>] = problem.xpath(<span class="hljs-string">&apos;//h2[@class=&quot;zm-item-title zm-editable-content&quot;]/text()&apos;</span>).extract()
        item[<span class="hljs-string">&apos;description&apos;</span>] = problem.xpath(<span class="hljs-string">&apos;//div[@class=&quot;zm-editable-content&quot;]/text()&apos;</span>).extract()
        item[<span class="hljs-string">&apos;answer&apos;</span>]= problem.xpath(<span class="hljs-string">&apos;//div[@class=&quot; zm-editable-content clearfix&quot;]/text()&apos;</span>).extract()
        <span class="hljs-keyword">return</span> item
</code></pre>
<h4 id="item&#x7C7B;&#x8BBE;&#x7F6E;">Item&#x7C7B;&#x8BBE;&#x7F6E;</h4>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> scrapy.item <span class="hljs-keyword">import</span> Item, Field

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ZhihuItem</span><span class="hljs-params">(Item)</span>:</span>
    <span class="hljs-comment"># define the fields for your item here like:</span>
    <span class="hljs-comment"># name = scrapy.Field()</span>
    url = Field()  <span class="hljs-comment">#&#x4FDD;&#x5B58;&#x6293;&#x53D6;&#x95EE;&#x9898;&#x7684;url</span>
    title = Field()  <span class="hljs-comment">#&#x6293;&#x53D6;&#x95EE;&#x9898;&#x7684;&#x6807;&#x9898;</span>
    description = Field()  <span class="hljs-comment">#&#x6293;&#x53D6;&#x95EE;&#x9898;&#x7684;&#x63CF;&#x8FF0;</span>
    answer = Field()  <span class="hljs-comment">#&#x6293;&#x53D6;&#x95EE;&#x9898;&#x7684;&#x7B54;&#x6848;</span>
    name = Field()  <span class="hljs-comment">#&#x4E2A;&#x4EBA;&#x7528;&#x6237;&#x7684;&#x540D;&#x79F0;</span>
</code></pre>
<h4 id="settingpy-&#x8BBE;&#x7F6E;&#x6293;&#x53D6;&#x95F4;&#x9694;">setting.py &#x8BBE;&#x7F6E;&#x6293;&#x53D6;&#x95F4;&#x9694;</h4>
<pre><code class="lang-python">BOT_NAME = <span class="hljs-string">&apos;zhihu&apos;</span>

SPIDER_MODULES = [<span class="hljs-string">&apos;zhihu.spiders&apos;</span>]
NEWSPIDER_MODULE = <span class="hljs-string">&apos;zhihu.spiders&apos;</span>
DOWNLOAD_DELAY = <span class="hljs-number">0.25</span>   <span class="hljs-comment">#&#x8BBE;&#x7F6E;&#x4E0B;&#x8F7D;&#x95F4;&#x9694;&#x4E3A;250ms</span>
</code></pre>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; BigCat all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x300C;Revision Time:
2017-02-05 22:37:52&#x300D;
</span></footer>
                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../file/part04/4.6.html" class="navigation navigation-prev " aria-label="Previous page: CrawlSpiders"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../file/part04/4.8.html" class="navigation navigation-next " aria-label="Next page: Downloader Middlewares"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-livereload/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"disqus":{"shortName":"gitbookuse"},"github":{"url":"https://github.com/dododream"},"search-pro":{"cutWordLib":"nodejieba","defineWord":["gitbook-use"]},"sharing":{"weibo":true,"facebook":true,"twitter":true,"google":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"tbfed-pagefooter":{"copyright":"Copyright © BigCat","modify_label":"「Revision Time:","modify_format":"YYYY-MM-DD HH:mm:ss」"},"baidu":{"token":"ff100361cdce95dd4c8fb96b4009f7bc"},"sitemap":{"hostname":"http://www.treenewbee.top"},"donate":{"wechat":"http://weixin.png","alipay":"http://alipay.png","title":"","button":"赏","alipayText":"支付宝打赏","wechatText":"微信打赏"},"edit-link":{"base":"https://github.com/dododream/edit","label":"Edit This Page"},"splitter":{},"toggle-chapters":{},"highlight":{},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book Python爬虫课程讲义 -->
</html>
